<template>
<!-- 生成一个盒子，第二层生成一个盒子，第三层左边生成一个盒子，右边生成一个盒子 -->
 <div class="login">
  <div class="login-box">
    <div class="login-left">
      <div class="login-title">欢迎登录</div>
    </div>
    <div class="login-right">
      <form @submit.prevent="handleLogin">
        <div class="form-group">
          <input v-model="username" type="text" placeholder="用户名" />
        </div>
        <div class="form-group">
          <input v-model="password" type="password" placeholder="密码" />
        </div>
        <div class="form-actions">
          <a href="#">忘记密码？</a>
        </div>
        <div class="form-buttons">
          <button type="submit">登录</button>
          <button type="button" @click="handleRegister">注册</button>
        </div>
        <div v-if="message" class="message">{{ message }}</div>
      </form>
    </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue'

const username = ref('')
const password = ref('')
const message = ref('')

function handleLogin() {
  if (!username.value || !password.value) {
    message.value = '请输入用户名和密码！'
    return
  }

  if (username.value === 'asd' && password.value === '123456') {
    alert('登录成功！')
  } else {
    message.value = '用户名或密码错误！'
  }
}
function handleRegister() {
  message.value = '注册.....'
}
</script>

<style scoped>
.login {
  min-height: 100vh;
  background-color: #409eff;
  background-image: url("../img/login-bg.png");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-box {
  background: #fff;
  width: 600px;
  height: 300px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  display: flex;
  overflow: hidden;
}
.login-left {
  width: 200px;
  background: #409eff;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.login-left img {
  width: 60px;
  margin-bottom: 10px;
}
.login-title {
  font-size: 20px;
  font-weight: bold;
}
.login-right {
  flex: 1;
  padding: 30px 24px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.form-group {
  margin-bottom: 16px;
}
.form-group input {
  width: 85%;
  padding: 8px 12px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 16px;
}
.form-actions {
  text-align: right;
  margin-bottom: 16px;
}
.form-actions a {
  color: #409eff;
  text-decoration: none;
  font-size: 14px;
  &:hover {
    text-decoration: underline;
  }
}
.form-buttons {
  display: flex;
  gap: 12px;
}
.form-buttons button {
  flex: 1;
  padding: 8px 0;
  border: none;
  border-radius: 4px;
  background: #409eff;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.2s;
}
.form-buttons button[type="button"] {
  background: #67c23a;
}
.form-buttons button:hover {
  opacity: 0.9;
}
.message {
  margin-top: 16px;
  color: #f56c6c;
  font-size: 14px;
  text-align: center;
}
</style>